/*
 * @Author: your name
 * @Date: 2021-10-11 21:14:23
 * @LastEditTime: 2021-10-11 21:32:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\1.5贪心\P3817\copy.cpp
 */
#include<bits/stdc++.h>
using namespace std;
long long ans; //一定要开long long!!!
int n,x,a[100002];
main() {
	cin>>n>>x; //输入
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<n;i++) //模拟,正着遍历
    	if(a[i]+a[i+1]>x) {  //如果相邻两盒>x
        	ans+=a[i+1]-x+a[i]; //就吃后面的
        	if(x < a[i]){
                a[i+1] = 0;
                a[i] = x;
            }else{
                a[i+1] = x-a[i];
            }
    	}
    for(int i=1;i<=n;i++){
        cout << a[i] << " ";
    }
    cout << endl;
	cout<<ans; //输出
	return 0;   
}